# Python 2.6.4
# Project Euler, Problem 64
# Copyright 2010 Talha Zaman

from math import sqrt
def fr(n):
    up1, down1, chain = 1, int(sqrt(n)), []
    while True:
        up2 = (n - down1**2) / up1
        if up2 == 0: break
        next = int((sqrt(n)+down1)/up2)
        chain.append(next)
        if next == 2*int(sqrt(n)): break
        down2 = next*up2 - down1
        up1, down1 = up2, down2
    return chain

print sum((len(fr(i)))%2 for i in xrange(1, 10001))
